package com.cloudshop.service.common.dto;

import java.io.Serializable;

/**
 * Rest 返回数据结构.
 *
 * @author 宫新程
 * @since 2019/3/31 13:08
 */
public class RestControllerResult<T> implements Serializable {

  private boolean success;

  private String errorMsg;

  private T data;

  public RestControllerResult() {}

  public RestControllerResult(boolean success, T data) {
    this.success = success;
    this.data = data;
  }

  public RestControllerResult(boolean success, String errorMsg) {
    this.success = success;
    this.errorMsg = errorMsg;
  }

  public RestControllerResult(boolean success, String errorMsg, T data) {
    this.success = success;
    this.errorMsg = errorMsg;
    this.data = data;
  }

  public static <T> RestControllerResult<T> success(T data) {
    return new RestControllerResult<>(true, data);
  }

  public static <T> RestControllerResult<T> error(String errorMsg) {
    return new RestControllerResult<>(false, errorMsg);
  }

  public boolean isSuccess() {
    return success;
  }

  public void setSuccess(boolean success) {
    this.success = success;
  }

  public String getErrorMsg() {
    return errorMsg;
  }

  public void setErrorMsg(String errorMsg) {
    this.errorMsg = errorMsg;
  }

  public T getData() {
    return data;
  }

  public void setData(T data) {
    this.data = data;
  }
}
